<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .nav{
            display: flex;
            width: 300px;
            height: 50px;
            line-height: 50px;
            text-align: center;
        }
        .nav-item{
            flex: 1;
        }
        .active{
            background-color: #dddddd;
        }



    </style>
</head>
<body>
    <div id="app">
        <div class="nav">
            <!-- 3、动态class  :class 判断 activeTab是否等于当前的-->
            <!-- 5、给每个nav-item动态绑定一个click事件 -->
            <div @click="handleClick('home')" :class="['nav-item',{active:activeTab==='home'}]">主页</div>
            <div @click="handleClick('introduce')" :class="['nav-item',{active:activeTab==='introduce'}]">公司介绍</div>
            <div @click="handleClick('product')" :class="['nav-item',{active:activeTab==='product'}]">产品介绍</div>
        </div>
        <div class="nav-content">
            <!-- 7、当前哪个activeTab就显示哪个子组件，用v-if判断是否显示 -->
            <div v-if="activeTab==='home'"><home></home></div>
            <div v-if="activeTab==='introduce'"><introduce></introduce></div>
            <div v-if="activeTab==='product'"><product></product></div>
        </div>

    </div>


    <script src="./node_modules/axios/dist/axios.js"></script>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
    // 2、定义三个不同的子组件
        Vue.component("home",{
            template:`
                <h1>主页</h1>
            `
        })
        Vue.component("introduce",{
            template:`
                <h1>公司介绍</h1>
            `
        })
        Vue.component("product",{
            template:`
                <h1>产品介绍</h1>
            `
        })
    // 1、定义父组件
        let vm=new Vue({
            el:"#app",
            data:{
                activeTab:"home",// 4、当前活动nav-item，默认是第一个home
            },
            methods:{
                // 6、点击 切换，让当前的this.activeTab等于当前的activeTab
                handleClick:function(activeTab){
                    this.activeTab=activeTab
                }

            }
        })











        
    </script>
</body>
</html>